/*
1.该文件是用于创建一个Count组件的reducer，reducer的本质是一个函数
2.reduce函数会接到两个参数，分别之前的状态preState,作动对象action
*/
import { INCREMENT,DECREMENT } from "./constant";
const initState = 0;

export default function countReducer(preState=initState,action){

    if(preState===undefined) preState = 0;

    const {type,data} = action;
    switch(type){
        case INCREMENT:
            return preState + data;
        case DECREMENT:
            return preState - data;
        default:
            return preState;
    }
}